package com.sina.shop.controller.home;

import com.sina.shop.domain.admin.Admin;
import com.sina.shop.service.admin.AdminService;
import com.sina.shop.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpSession;

/**
 * Created with IntelliJ IDEA.
 * Description:  此controller只是负责简单的页面跳转
 * 段浩杰   2018-03-06-15:46
 */
@Controller
@RequestMapping(value = "home")
public class HomeController extends BaseController {


    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "pay", method = RequestMethod.GET)
    public ModelAndView pay() {
        ModelAndView modelAndView = new ModelAndView("/home/pay");

        return modelAndView;
    }

    @RequestMapping(value = "product", method = RequestMethod.GET)
    public ModelAndView product() {
        ModelAndView modelAndView = new ModelAndView("/home/product");

        return modelAndView;
    }


    @RequestMapping(value = "search", method = RequestMethod.GET)
    public ModelAndView search() {
        ModelAndView modelAndView = new ModelAndView("/home/search");

        return modelAndView;
    }


    @RequestMapping(value = "shopCar", method = RequestMethod.GET)
    public ModelAndView shopCar() {
        ModelAndView modelAndView = new ModelAndView("/home/shopCar");

        return modelAndView;
    }

    @RequestMapping(value = "success", method = RequestMethod.GET)
    public ModelAndView success() {
        ModelAndView modelAndView = new ModelAndView("/home/success");

        return modelAndView;
    }

    @RequestMapping(value = "login", method = RequestMethod.POST)
    public ModelAndView index(Admin admin, HttpSession session) {
        ModelAndView modelAndView = new ModelAndView("index");
        admin=adminService.getAdmin1(admin.getAccount());
        session.setAttribute("name", admin.getName());
        return modelAndView;
    }
}
